package com.stp.kafka.callback;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.kafka.support.SendResult;
import org.springframework.stereotype.Component;
import org.springframework.util.concurrent.ListenableFutureCallback;

@Slf4j
@AllArgsConstructor
public class KafkaTestListenableFutureCallback implements ListenableFutureCallback<SendResult<String, Object>> {
    @Override
    public void onFailure(Throwable ex) {
        log.error("发送消息失败1:" + ex.getMessage());
    }

    @Override
    public void onSuccess(SendResult<String, Object> success) {
        // 消息发送到的topic
        String topic = success.getRecordMetadata().topic();
        // 消息发送到的分区
        int partition = success.getRecordMetadata().partition();
        // 消息在分区内的offset
        long offset = success.getRecordMetadata().offset();
        log.info("发送消息成功1:" + topic + "-" + partition + "-" + offset);
    }
}
